package com.manage.competition.service.impl;

import com.manage.competition.entity.FillInItem;
import com.manage.competition.mapper.FillInItemMapper;
import com.manage.competition.repository.FillInItemRepository;
import com.manage.competition.service.IFillInItemService;
import com.manage.competition.util.CurrentUserUtil;
import com.manage.competition.util.SnowflakeUtil;
import com.manage.competition.vo.FillInItemVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * Create with IDEA
 *
 * @Author: gitee.com/KamisamaXX
 * @Date: Create in 17:27 2019/3/29
 * @Description:
 */
@Service
public class FillInItemServiceImpl implements IFillInItemService {

    @Autowired
    private FillInItemMapper fillInItemMapper;

    @Autowired
    private FillInItemRepository fillInItemRepository;
    @Override
    public int insert(FillInItem fillInItem) {
        fillInItem.setId(SnowflakeUtil.nextId());
        fillInItem.setCreateUser(CurrentUserUtil.getCurrentUser().getUsername());
        fillInItem.setUpdateUser(CurrentUserUtil.getCurrentUser().getUsername());
        return fillInItemMapper.insert(fillInItem);
    }

    @Override
    public List<FillInItemVo> findBySignupInfo(long id) {
        List<FillInItem> list = fillInItemRepository.findAllBySignupInformationId(id);
        List<FillInItemVo> res = new ArrayList<>();
        for (FillInItem item:
             list) {
            FillInItemVo vo = new FillInItemVo();
            BeanUtils.copyProperties(item,vo);
            res.add(vo);
        }
        return res;
    }

    @Override
    public int deleteOption(long id) {
        return fillInItemMapper.deleteByPrimaryKey(id);
    }


}
